package awesome.cpu.control;

import awesome.cpu.utils.Mode;

public class Clock {
	
	private final static boolean outputDebug = true;
	
	private static int INTERVAL = 1000;
	private final static Clock mInstance = new Clock();
	
	private boolean mRunning = true;
	
	private Clock() {}
	
	public static Clock getInstance() {
		return mInstance;
	}
	
	public void setClockCycle(int length) {
		INTERVAL = length;
	}
	
	void stopRunning() {
		mRunning = false;
	}
	
	public void start() {
		mRunning = true;
		new Thread() {
			@Override
			public void run() {
				while (mRunning) {
					try {
						if (outputDebug && Mode.getDebugLevel() >= Mode.DEBUG_LEVEL_PRINT_ALL) {
							System.out.println("============================");
						}
						synchronized (Clock.this) {
							Clock.this.notifyAll();
						}
						Thread.sleep(INTERVAL);
					} catch (InterruptedException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
				}
			}
		}.start();
	}
}